﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PlanningGIS.Framework.Config;
using PlanningGIS.ManageUtility;
using PlanningGIS.Util.Log;

namespace PlanningGIS.Framework.Controls
{
    /// <summary>
    /// 开始启动选项
    /// </summary>
    public class StartHelper
    {
        /// <summary>
        /// 系统启动
        /// </summary>
        /// <returns></returns>
        public static bool StartApp()
        {
            AppConfig.IsRunLocal = ConfigurationManager.AppSettings.Get("单机运行").Equals("true", StringComparison.CurrentCultureIgnoreCase);
            ManageHelper.DBContext = DbConnectHelper.CreateDbContextByIntance("MT");
            FrameworkHelper.SysName = ConfigurationManager.AppSettings.Get("SysName");
            if (AppConfig.IsRunLocal)
            {
                FrameworkHelper.CurrentUser = new ManageUtility.Modules.User()
                {
                    Login_Name = ManageHelper.Administrator,
                    Name = "单机版用户"
                };
                return true;
            }
            else
            {
                
                FrmLogin frm = new FrmLogin();
                if (frm.ShowDialog() != DialogResult.OK)
                {
                    System.Diagnostics.Process.GetCurrentProcess().Kill();
                    return false;
                }
                return true;
            }
        }

    }
}
